﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Wap/Shop/ShopSite.Master" AutoEventWireup="true" CodeBehind="ShoppingCart_old.aspx.cs" Inherits="ZLCMS.Web.Wap.Shop.ShoppingCart_old" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
	<title>我的购物车</title>
 <style type="text/css">
    #mypage .my_cart .ui-checkbox .ui-btn{ background:none; border:none; margin-top:90%; }
	#mypage .ui-checkbox .ui-btn{ background:#fff; border:1px solid #fff;}
	#mypage .my_cart .ui-checkbox .ui-btn.ui-checkbox-off{ background:#fff; }
	.my_cart .ui-btn-icon-left{ padding-left:0px;}
	.ui-input-text{ box-shadow:none; margin:0; border:none; border-radius:0; height:23px; line-height:23px;}
	.ui-input-text input{ text-align:center;}
	.cart_footer .ui-checkbox input{ display:none;}
	.n1,.n2{ float:left; margin-right:5px;}
	#mypage .num .ui-input-text{ height:26px;}
	#mypage .num a{ height:26px; line-height:20px;}
	#mypage .num .ui-input-text input{ min-height:26px; height:26px;}
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="pages" runat="server">

<!--S page -->
<div data-role="page" id="mypage">

	<!--S header -->
	<div data-role="header">
	</div>
    <!--E header -->
	
    <!--S content -->
	<div role="main" class="ui-content">
        
		<!--s my_cart-->
        <div class="listviewHandler">
        </div>
        <!--e my_cart-->

        
        <div class="cart_delete" style="display:none"><a href="#" onclick="removeProduct($(this));"><img src="images/cart_delete.png">删除勾选商品</a></div>

 	</div>
    <!--E content -->
	
    <!--S footer -->
	<div data-role="footer" data-position="fixed" data-tap-toggle="false">
    	<div class="cart_footer">
    	<table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="25%" align="center">
                <label>
                <input id="selAll" onchange="$('input[sel]').prop('checked',$(this).prop('checked')).checkboxradio('refresh');updateAll();" type="checkbox"/>全选
                </label>
                    
            </td>
            <td align="left">
            	<h2>总计：<span>￥</span><span id="totalPrice">0</span></h2>
<%--                <p>(共<span id="totalCount">0</span>件)</p>--%>
            </td>
            <td><a href="#" class="cartbtn" onclick="submitOrder($(this));">结算</a></td>
          </tr>
        </table>
        </div>
    </div>
    <!--E footer -->
</div>
<!--E page -->

<script src="/wap/lib/common/listviewHandler.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        var handler = $('.listviewHandler').listviewHandler();
        handler.initialize({
            loaderBtn: $('#moreBtn'), //加载数据按钮（点击加载下一页）
            emptyHtml: '<div class="my_cart" style="height: 20px;"><div class="center"> 无记录</div></div>', //无记录时显示此html
            itemTemplate: '<div class="my_cart">' +
        	'<div class="input">' +
                '<label>' +
                   ' <input type="checkbox" onchange="updateAll();" sel="{ProductSkuCode}">' +
               ' </label>' +
           ' </div>' +
            '<div class="left"><img src="{ImageUrl}"></div>' +
            '<div class="center">' +
               ' <h2>{ProductName}{SkuHtml}</h2>' +
               ' <p>单价：<span>￥{UnitPrice}</span></p>' +
                '<div class="cart_num">' +
                    '<div class="num">' +
//                    	'<div class="n1">数量</div>' +
                        '<div class="n2"><a href="#" id="min1" onclick="increaseNumber(-1,\'{ProductSkuCode}\')">-</a><input UnitPrice="{UnitPrice}"  type="text" value="{ProductCount}" name="{ProductSkuCode}" id="text_box1" onblur="setNumber(\'{ProductSkuCode}\')" /><a href="#" id="add1" onclick="increaseNumber(1,\'{ProductSkuCode}\')">+</a></div>' +
                    '</div>' +
                '</div>' +
           ' </div>' +
           ' <div class="right"><a href="ProductDetail.aspx?no={ProductNo}" data-ajax="false"><img src="images/usercenter_righticon.png"></a></div>' +
            '<div class="clear"></div>' +
       ' </div>', //项模板
            pageIndex: 1, //页码（从1起算）
            pageSize: 20, //页大小
            totalCount: 999, //总记录数
            itemHandler: function (data, itemTemplate, container) {//数据各项处理
                var skuHtml = '';
                var skuData = $.parseJSON(data.ParamCode);
                $(skuData).each(function () { skuHtml += '<span>【' + this.ItemName + '】</span>'; });
                data.SkuHtml = skuHtml;

                data.ImageUrl = firstFilePath(data.ImageUrl);
                return itemTemplate.format(data);
            },
            beforeHandleResult: function (result, totalCount, container) {
                if (totalCount > 0) {
                    $('.cart_delete').show();
                }
                $('#totalPrice').text(result.TotalProductPrice);
                $('#totalCount').text(result.TotalProductCount);
            },
            afterHandleResult: function (result, totalCount, container) {
                if (totalCount == 0) {
                    location.href = "EmptyShoppingCart.aspx";
                    return;
                }
                $('.listviewHandler').trigger('create');
                $('#selAll').prop("checked", true).checkboxradio("refresh");
                $('#selAll').trigger('change');
            },
            command: 'Member.LoadShoppingCart',
            parameter: { MemberAccount: '<%=CurrentMemberAccount %>',Kind:'<%=Kind %>' }
        });
        handler.nextPage();
    });


    function increaseNumber(factor, sku) {
        var currentVal = parseInt($("input[name=" + sku + "]").val()) + factor;
        $("input[name=" + sku + "]").val(currentVal);
        setNumber(sku);
    }

    function setNumber(sku) {
        var currentVal = parseInt($("input[name=" + sku + "]").val());
        if (isNaN(currentVal)) currentVal = 1;
        if (currentVal < 1) currentVal = 1;
        if (currentVal > 99) currentVal = 99;
        $("input[name=" + sku + "]").val(currentVal);
        $("input[name=" + sku + "]").executeCommand({
            successCallBack: function (result) {
                //$('#totalPrice').text(result.TotalProductPrice);
                //$('#totalCount').text(result.TotalProductCount);
                updateAll();
            }
        }, 'Member.SelectProduct', { MemberAccount: '<%=CurrentMemberAccount %>', ProductList: [{ ProductSkuCode: sku, Counter: currentVal, Increment: 0}] });

    }

    //同步全选按钮
    function updateAll() {
        var check = true;
        var totalPrice = 0;
        $('input[sel]').each(function () {
            if ($(this).prop('checked') == false) {
                check = false;
            } else {
                var cntInput = $("[UnitPrice]", $(this).parents("div.my_cart"));
                totalPrice += parseInt(cntInput.val()) * cntInput.attr('UnitPrice');
            }
        });
        $('#selAll').prop("checked", check).checkboxradio("refresh")
        $('#totalPrice').text(totalPrice.toFixed(2));
    }

    //删除产品
    function removeProduct(ui) {
        confirmDialog('请确定要删除勾选的商品', function () {
            var skuList = [];
            $('input[sel]:checked').each(function () {
                skuList.push($(this).attr('sel'));
            });
            if (skuList.length == 0) {
                showTips("没有勾选的商品",1500); return;
            }
            ui.executeCommand({
                successCallBack: function (result) {
                    showTips('操作成功！', 500, function () { location.reload(); });
                }
            }, 'Member.RemoveProduct', { MemberAccount: '<%=CurrentMemberAccount %>', SkuCodeList: skuList });

        });
    }

    //提交订单
    function submitOrder(ui) {
        var skuList = [];
        $('input[sel]:checked').each(function () {
            skuList.push($(this).attr('sel'));
        });
        if(skuList.length == 0){showTips('请选择要结算的产品');return;}
        ui.executeCommand({
            successCallBack: function (result) {
                location.href = 'SubmitOrder.aspx';
            }
        }, 'Member.ConfirmSelectProduct', { MemberAccount: '<%=CurrentMemberAccount %>', SkuCodeList: skuList });
    }
</script>

</asp:Content>
